package test;

import java.io.File;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class imageFilter {
	public static void main(String[] args) throws SQLException {
		Connection con=DAO.DbcpConnection.getConnection();
		Statement st=con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_UPDATABLE);
		String sql="select * from newshoes";
		ResultSet rs=st.executeQuery(sql);
		boolean flag=false;
		int i=0;
		while (rs.next()) {
			System.out.println(i++);
			flag=false;
			long uukey=rs.getLong("uukey");
			String left=rs.getString("leftimage");
			String right=rs.getString("rightimage");
			String middle=rs.getString("middleimage");
			if(left!=null){
				if(!ifImage(left)){
					rs.updateString("leftimage", null);
					etc.GlobConf.loger.info("["+uukey+"]"+left);
					flag=true;
				}
			}
			if(right!=null){
				if(!ifImage(middle)){
					rs.updateString("middleimage", null);
					etc.GlobConf.loger.info("["+uukey+"]"+middle);
					flag=true;
				}

			}
			if(middle!=null){
				if(!ifImage(right)){
					rs.updateString("rightimage", null);
					etc.GlobConf.loger.info("["+uukey+"]"+right);
					flag=true;
				}
			}
			if(flag){
				rs.updateInt("done", 1);
				rs.updateRow();
			}
		}
	}

	private static boolean ifImage(String path) {
		String root="W://";
		File file=new File(root+path);
		if(file.exists()){
			if(file.length()<1000){
				return false;
			}
		}
		return true;
	}
}
